# -*- coding: utf-8 -*-
'''
Created on 2012-1-15

@author: y
'''


from django import forms
from django.forms import ModelForm,Textarea,HiddenInput
#from django.forms import ModelForm
from sprt.approved.models import Approve


import datetime


class ApproveForm(ModelForm):
#    schedule=forms.IntegerField(widget=HiddenInput())
    content=forms.CharField(label=u'内容',widget=Textarea(attrs={'cols':80,'rows':20}))

    class Meta:
        model = Approve
#        fields = ('content','schedule')
        fields = ('content',)
    
    def commit_approve(self, _schedule, created_by):
        self.instance.status = 1
        self.instance.commit_date = datetime.datetime.now()
        self.save_form(_schedule,created_by,True)
    
    def save_form(self, _schedule, created_by, commit=False):
        self.instance.schedule = _schedule
        self.instance.created_by = created_by
        self.save(True)
        if commit:
            self.instance.schedule.status = 2 #0-compose 1-commit 2-approved 3-reviewed
            self.instance.schedule.save()
